home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Cafe 3
/
Visual Cafe 3.ISO
/
Vcafe
/
Main.bin
/
VariablePrintln.java
< prev
next >
Wrap
Text File
|
1998-09-29
|
3KB
|
65 lines
import java.lang.*;
import com.symantec.itools.vcafe.macro.VisualCafeCommand;
import com.symantec.itools.vcafe.openapi.*;
/*
Variable Println Macro
VCafe macro that creates a System.out.println with the variable
that the cursor is currently on. If the cursor is not on a word
it will make a println with empty quotes.
*/
public class VariablePrintln extends java.lang.Object
{
com.symantec.itools.vcafe.openapi.VisualCafe vcMainCafe;
com.symantec.itools.vcafe.openapi.SourceFile sfSource;
public void run()
{
com.symantec.itools.vcafe.openapi.Range rSelectedWord, rCurrentPos; //Positons of cursor
Object oFrontMostWin; //The source file working with
String sVarSelected; //The variable the cursor is on
StringBuffer sbRange; //The Range that has the selected var
StringBuffer sbThePrintln; //VCafe Open API uses stringbuffer
String sVarLn; //The line to insert
sVarSelected = "";
// 1. Get the open source window
vcMainCafe = VisualCafe.getVisualCafe();
oFrontMostWin = vcMainCafe.getFrontmostWindow();
if(! (oFrontMostWin instanceof SourceFile)) return; // A source window doesn't have focus
else sfSource = (SourceFile)oFrontMostWin;
// 2. Get the variable that the cursor is on
VisualCafeCommand.textSelectWord();
rSelectedWord = sfSource.getSelectionRange();
sbRange = sfSource.getRangeText(rSelectedWord);
sVarSelected = sbRange.toString();
// 3. Insert println statement with the selected variable
VisualCafeCommand.textEndOfLine();
VisualCafeCommand.textEnter();
rCurrentPos = sfSource.getSelectionRange();
if(sVarSelected.equals(""))//No variable selected so just print an empty println();
{
sVarLn = "\"\"";
sbThePrintln = new StringBuffer("System.out.println("+sVarLn+");");
sfSource.setRangeText(sbThePrintln, rCurrentPos);
VisualCafeCommand.textEndOfLine(); //Position the cursor in the quotes
VisualCafeCommand.textCursorLeft();
VisualCafeCommand.textCursorLeft();
VisualCafeCommand.textCursorLeft();
}
else
{
sVarLn = "\""+sVarSelected+": \"+"+sVarSelected;
sbThePrintln = new StringBuffer("System.out.println("+sVarLn+");");
sfSource.setRangeText(sbThePrintln, rCurrentPos);
VisualCafeCommand.textEndOfLine(); //Position cursor at the end of line
}
}
}